﻿namespace Jodell.Transport.Ethercat
{
    public static class Constants
    {
        /** max. entries in EtherCAT error list */
        public const int EC_MAXELIST = 64;
        /** max. length of readable name in slavelist and Object Description List */
        public const int EC_MAXNAME = 40;
        /** max. number of slaves in array */
        public const int EC_MAXSLAVE = 200;
        /** max. number of groups */
        public const int EC_MAXGROUP = 2;
        /** max. number of IO segments per group */
        public const int EC_MAXIOSEGMENTS = 64;
        /** max. mailbox size */
        public const int EC_MAXMBX = 1486;
        /** max. eeprom PDO entries */
        public const int EC_MAXEEPDO = 0x200;
        /** max. SM used */
        public const int EC_MAXSM = 8;
        /** max. FMMU used */
        public const int EC_MAXFMMU = 4;
        /** max. Adapter */
        public const int EC_MAXLEN_ADAPTERNAME = 128;

        /** return value no frame returned */
        public const int EC_NOFRAME = -1;
        /** return value unknown frame received */
        public const int EC_OTHERFRAME = -2;
        /** return value general error */
        public const int EC_ERROR = -3;
        /** return value too many slaves */
        public const int EC_SLAVECOUNTEXCEEDED = -4;
        /** return value request timeout */
        public const int EC_TIMEOUT = -5;
        /** maximum EtherCAT frame length in bytes */
        public const int EC_MAXECATFRAME = 1518;
        /** maximum EtherCAT LRW frame length in bytes */
        /* MTU - Ethernet header - length - datagram header - WCK - FCS */
        public const int EC_MAXLRWDATA = (EC_MAXECATFRAME - 14 - 2 - 10 - 2 - 4);
        /** size of DC datagram used in first LRW frame */
        public const int EC_FIRSTDCDATAGRAM = 20;
        /** standard frame buffer size in bytes */
        public const int EC_BUFSIZE = EC_MAXECATFRAME;
        /** datagram type EtherCAT */
        public const int EC_ECATTYPE = 0x1000;
        /** number of frame buffers per channel (tx, rx1 rx2) */
        public const int EC_MAXBUF = 16;
        /** timeout value in us for tx frame to return to rx */
        public const int EC_TIMEOUTRET = 2000;
        /** timeout value in us for safe data transfer, max. triple retry */
        public const int EC_TIMEOUTRET3 = (EC_TIMEOUTRET * 3);
        /** timeout value in us for return "safe" variant (f.e. wireless) */
        public const int EC_TIMEOUTSAFE = 20000;
        /** timeout value in us for EEPROM access */
        public const int EC_TIMEOUTEEP = 20000;
        /** timeout value in us for tx mailbox cycle */
        public const int EC_TIMEOUTTXM = 20000;
        /** timeout value in us for rx mailbox cycle */
        public const int EC_TIMEOUTRXM = 700000;
        /** timeout value in us for check statechange */
        public const int EC_TIMEOUTSTATE = 2000000;
        /** size of EEPROM bitmap cache */
        public const int EC_MAXEEPBITMAP = 128;
        /** size of EEPROM cache buffer */
        public const int EC_MAXEEPBUF = EC_MAXEEPBITMAP << 5;
        /** default number of retries if wkc <= 0 */
        public const int EC_DEFAULTRETRIES = 3;
        /** default group size in 2^x */
        public const int EC_LOGGROUPOFFSET = 16;
    }
}
